package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.CommonPlaceDto;
import com.enjoyor.soa.traffic.api.dto.tsms.PoliceAssessDto;
import com.enjoyor.soa.traffic.api.dto.tsms.RltRouteDeviceDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.ICommonPlaceConsumeService;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.IPoliceAssessConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/policeAssess" })
@Api("PoliceAssessController相关api")
@CrossOrigin
public class PoliceAssessController {

	@Autowired IPoliceAssessConsumeService iPoliceAssessConsumeService;
	
	/**
	 * 警员考核分页查询；
	 * @param page 分页参数
	 * @return zyh
	 */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @GetMapping(value = { "/getPoliceAssessPage" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("警员考核信息分页")
    	@ApiImplicitParams({
        @ApiImplicitParam(name = "assessId", value = "考核编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "policeId", value = "警员编号", paramType = "query", dataType = "string") })
    public ResultPojo getCommonPlacePage(
    		@RequestParam(defaultValue = "")String assessId, 
			@RequestParam(defaultValue = "") String executeTaskId,
			@RequestParam(defaultValue = "") String policeId,  
    		Page page, HttpServletRequest request){
    	ResultPojo resultPojo = new ResultPojo();
    	resultPojo = iPoliceAssessConsumeService.getPoliceAssessPage(page, assessId, executeTaskId, policeId);
    	return resultPojo;
    }
    
    /**
	 * 获取警员考核List
	 * @return zyh
	 */
	@GetMapping(value = { "/getPoliceAssessList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response=PoliceAssessDto.class, code = 0, message = "")
    @ApiOperation("警员考核列表信息查询")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "assessId", value = "考核编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "policeId", value = "警员编号", paramType = "query", dataType = "string")})
	public ResultPojo getPoliceAssessList(
			@RequestParam(defaultValue = "")String assessId, 
			@RequestParam(defaultValue = "") String executeTaskId,
			@RequestParam(defaultValue = "") String policeId, 
    		HttpServletRequest request) {
		return iPoliceAssessConsumeService.getPoliceAssessList(assessId, executeTaskId, policeId);
	}
	
	/**
	 * 添加警员考核；
	 * @param commonPlaceDto
	 * @param request
	 * @return
	 */
	@PostMapping(value = { "/addPoliceAssess" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加警员考核")
	public ResultPojo addPoliceAssess(
			@RequestBody PoliceAssessDto policeAssessDto, HttpServletRequest request) {
			return iPoliceAssessConsumeService.insertPoliceAssess(policeAssessDto,
					((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	@PutMapping(value = { "/editPoliceAssess" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改警员考核")
	public ResultPojo editCommonPlace(@RequestBody PoliceAssessDto policeAssessDto, HttpServletRequest request) {
			return iPoliceAssessConsumeService.editPoliceAssess(policeAssessDto,
					((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	
	@DeleteMapping(value = { "/delPoliceAssess" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除警员考核信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "assessId", value = "考核编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "executeTaskId", value = "执行任务编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "policeId", value = "警员编号", paramType = "query", dataType = "string")})
    public ResultPojo delCommonPlace(
    		@RequestParam(defaultValue = "") String assessId,
    		@RequestParam(defaultValue = "") String executeTaskId,
    		@RequestParam(defaultValue = "") String policeId, HttpServletRequest request) {
        return iPoliceAssessConsumeService.deletePoliceAssess(assessId, executeTaskId, policeId,
        		((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	/**
	 * 考核打分
	 * @return zyh
	 */
	@DeleteMapping(value = { "/assessItmesScore" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody   
    @ApiOperation("考核打分")
	@ApiImplicitParams({@ApiImplicitParam(name = "list", value = "考核得分集合", paramType = "query", allowMultiple=true)})
    public ResultPojo assessItmesScore(
    		@RequestBody PoliceAssessDto policeAssessDto,
    		@RequestParam("list") String list, HttpServletRequest request) {
        return iPoliceAssessConsumeService.assessPoliceScore(policeAssessDto,list, 
        		((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

}
